#include "key.h"
#include "io430.h"
#include "led.h"

char KEYL_D=0;
char KEYR_D=0;
char KEYL_U=0;
char KEYR_U=0;

void KEY_INIT(){
  // input
  P1DIR &= ~BIT1;
  P2DIR &= ~BIT1;
  // enable pull 
  P1REN |= BIT1;
  P2REN |= BIT1;
  // pull up
  P1OUT |= BIT1;
  P2OUT |= BIT1;

  P1IE |= BIT1;
  P2IE |= BIT1;
  
  P1IES |= BIT1;
  P2IES |= BIT1;
  
  P1IFG &= ~BIT1;
  P2IFG &= ~BIT1;
}

#pragma vector = PORT1_VECTOR
__interrupt void Port1_IST(void){
      if(P1IFG & BIT1){
            P1IFG &= ~BIT1; // clear flag
            if(!KEYR_D)  KEYR_D = 1; 
      }
}

#pragma vector = PORT2_VECTOR
__interrupt void Port2_IST(void){
      if(P2IFG & BIT1){
            P2IFG &= ~BIT1; // clear flag
            if(!KEYL_D)  KEYL_D = 1; 
      }
}
